home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / ImageLight / ImageLight.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  10.7 KB  |  486 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Cursor;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.MediaTracker;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13. import java.awt.image.MemoryImageSource;
  14. import java.awt.image.PixelGrabber;
  15. import java.net.MalformedURLException;
  16. import java.net.URL;
  17. import java.net.URLEncoder;
  18.  
  19. public class ImageLight extends Applet implements Runnable, MouseListener {
  20.    boolean loaded;
  21.    Thread thread;
  22.    Image image;
  23.    Image buffer;
  24.    // $FF: renamed from: b java.awt.Graphics
  25.    Graphics field_0;
  26.    Color backColor;
  27.    Color color;
  28.    // $FF: renamed from: wi int
  29.    int field_1;
  30.    // $FF: renamed from: he int
  31.    int field_2;
  32.    int wiIm;
  33.    int heIm;
  34.    int pause;
  35.    // $FF: renamed from: R int
  36.    private int field_3;
  37.    // $FF: renamed from: G int
  38.    private int field_4;
  39.    // $FF: renamed from: B int
  40.    private int field_5;
  41.    int step;
  42.    int rad;
  43.    // $FF: renamed from: lX int
  44.    private int field_6;
  45.    // $FF: renamed from: lY int
  46.    private int field_7;
  47.    static int[] pix;
  48.    static int[] pixnew;
  49.    // $FF: renamed from: sx int
  50.    int field_8;
  51.    // $FF: renamed from: sy int
  52.    int field_9;
  53.    private String statusBarText;
  54.    private AudioClip sound;
  55.    private AudioClip clicSound;
  56.    private AudioClip enterSound;
  57.    private boolean loopSound;
  58.    private String link;
  59.    // $FF: renamed from: fm java.awt.FontMetrics
  60.    private FontMetrics field_10;
  61.    private String enterText;
  62.    private boolean isEnterTextEnabled;
  63.    private int wiEnterText;
  64.    private int enterTextHeight;
  65.    private Color enterTextColor;
  66.    private int decx;
  67.    private int decy;
  68.  
  69.    public String getAppletInfo() {
  70.       return "Name: ImageLight\r\nAuthor: Taiji Software\r\n";
  71.    }
  72.  
  73.    public ImageLight() {
  74.       this.backColor = Color.black;
  75.       this.pause = 50;
  76.       this.step = 10;
  77.       this.rad = 50;
  78.       this.color = new Color(210, 220, 130);
  79.       ((Component)this).addMouseListener(this);
  80.    }
  81.  
  82.    public void register() {
  83.       try {
  84.          URL u = new URL("http://www.taijisoftware.com");
  85.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  86.          this.stop();
  87.       } catch (Exception e) {
  88.          System.out.println(e);
  89.          this.stop();
  90.       }
  91.    }
  92.  
  93.    public void init() {
  94.       String codeBase = null;
  95.  
  96.       try {
  97.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  98.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  99.          codeBase = codeBase.toUpperCase();
  100.       } catch (Exception var11) {
  101.       }
  102.  
  103.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  104.          String regCode = ((Applet)this).getParameter("registration_code");
  105.          if (regCode == null) {
  106.             regCode = ((Applet)this).getParameter("reg_domain");
  107.             if (regCode == null) {
  108.                this.register();
  109.             } else {
  110.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  111.                   codeBase = "WWW." + codeBase;
  112.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  113.                   codeBase = codeBase.substring(4);
  114.                }
  115.  
  116.                char[] chars = new char[codeBase.length()];
  117.                codeBase.getChars(0, codeBase.length(), chars, 0);
  118.                String key = new String("haricot");
  119.                char[] chars2 = new char[key.length()];
  120.                key.getChars(0, key.length(), chars2, 0);
  121.  
  122.                for(int i = 0; i < codeBase.length(); ++i) {
  123.                   int j;
  124.                   if (i >= key.length()) {
  125.                      j = i - key.length() * (i / key.length());
  126.                   } else {
  127.                      j = i;
  128.                   }
  129.  
  130.                   chars[i] += chars2[j];
  131.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  132.                }
  133.  
  134.                String res = new String(chars);
  135.                if (!res.equalsIgnoreCase(regCode)) {
  136.                   this.register();
  137.                }
  138.             }
  139.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  140.             this.register();
  141.          }
  142.       }
  143.  
  144.       this.getParameters();
  145.       int rgb = this.color.getRGB();
  146.       this.field_3 = (rgb & 16711680) >> 16;
  147.       this.field_4 = (rgb & '\uff00') >> 8;
  148.       this.field_5 = rgb & 255;
  149.       this.image = ((Applet)this).getImage(((Applet)this).getCodeBase(), ((Applet)this).getParameter("image_name"));
  150.       MediaTracker tracker = new MediaTracker(this);
  151.       tracker.addImage(this.image, 0);
  152.  
  153.       try {
  154.          tracker.waitForAll();
  155.          tracker.isErrorAny();
  156.       } catch (Exception e) {
  157.          System.err.println(e);
  158.       }
  159.  
  160.       if (!this.loaded) {
  161.          this.stop();
  162.       }
  163.  
  164.       this.wiIm = this.image.getWidth(this);
  165.       this.heIm = this.image.getHeight(this);
  166.       this.decx = (this.field_1 - this.wiIm) / 2;
  167.       this.decy = (this.field_2 - this.heIm) / 2;
  168.       this.field_6 = this.wiIm / 2;
  169.       this.field_7 = this.heIm / 2;
  170.       pix = new int[this.wiIm * this.heIm];
  171.       pixnew = new int[this.wiIm * this.heIm];
  172.       PixelGrabber pixg = new PixelGrabber(this.image, 0, 0, this.wiIm, this.heIm, pix, 0, this.wiIm);
  173.  
  174.       try {
  175.          pixg.grabPixels();
  176.       } catch (InterruptedException var9) {
  177.       }
  178.  
  179.       this.image = ((Component)this).createImage(new MemoryImageSource(this.wiIm, this.heIm, pixnew, 0, this.wiIm));
  180.       this.buffer = ((Component)this).createImage(this.field_1, this.field_2);
  181.       this.field_0 = this.buffer.getGraphics();
  182.       this.field_0.setColor(this.enterTextColor);
  183.       String fontName = ((Applet)this).getParameter("enter_text_font");
  184.       if (fontName == null) {
  185.          fontName = "TimesRoman";
  186.       }
  187.  
  188.       int style = 1;
  189.       String s = ((Applet)this).getParameter("enter_text_style");
  190.       if (s != null) {
  191.          if (s.equals("bold")) {
  192.             style = 1;
  193.          } else if (s.equals("italic")) {
  194.             style = 2;
  195.          } else if (s.equals("bold_italic")) {
  196.             style = 3;
  197.          } else {
  198.             style = 0;
  199.          }
  200.       }
  201.  
  202.       this.field_0.setFont(new Font(fontName, style, this.enterTextHeight));
  203.       this.field_10 = this.field_0.getFontMetrics();
  204.       if (this.enterText != null) {
  205.          this.wiEnterText = this.field_10.stringWidth(this.enterText);
  206.       }
  207.  
  208.       if (this.sound != null) {
  209.          if (this.loopSound) {
  210.             this.sound.loop();
  211.             return;
  212.          }
  213.  
  214.          this.sound.play();
  215.       }
  216.  
  217.    }
  218.  
  219.    public void getParameters() {
  220.       this.field_1 = ((Component)this).getSize().width;
  221.       this.field_2 = ((Component)this).getSize().height;
  222.       String s = ((Applet)this).getParameter("pause");
  223.       if (this.getColor("color") != null) {
  224.          this.color = this.getColor("color");
  225.       }
  226.  
  227.       if (s != null) {
  228.          this.pause = Integer.parseInt(s);
  229.       }
  230.  
  231.       s = ((Applet)this).getParameter("light_step");
  232.       if (s != null) {
  233.          this.step = Integer.parseInt(s);
  234.       }
  235.  
  236.       s = ((Applet)this).getParameter("light_rad");
  237.       if (s != null) {
  238.          this.rad = Integer.parseInt(s);
  239.       }
  240.  
  241.       ((Component)this).setBackground(this.getColor("background_color"));
  242.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  243.       s = ((Applet)this).getParameter("sound_name");
  244.       if (s != null) {
  245.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  246.       }
  247.  
  248.       s = ((Applet)this).getParameter("loop_sound");
  249.       if (s != null) {
  250.          if (s.equals("yes")) {
  251.             this.loopSound = true;
  252.          } else {
  253.             this.loopSound = false;
  254.          }
  255.       }
  256.  
  257.       s = ((Applet)this).getParameter("clic_sound_name");
  258.       if (s != null) {
  259.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  260.       }
  261.  
  262.       s = ((Applet)this).getParameter("enter_sound_name");
  263.       if (s != null) {
  264.          this.enterSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  265.       }
  266.  
  267.       this.link = ((Applet)this).getParameter("link");
  268.       this.enterText = ((Applet)this).getParameter("enter_text");
  269.       s = ((Applet)this).getParameter("enter_text_height");
  270.       if (s != null) {
  271.          this.enterTextHeight = Integer.parseInt(s);
  272.       }
  273.  
  274.       this.enterTextColor = this.getColor("enter_text_color");
  275.       if (this.enterTextColor == null) {
  276.          this.enterTextColor = Color.white;
  277.       }
  278.  
  279.    }
  280.  
  281.    public Color getColor(String param) {
  282.       String s = ((Applet)this).getParameter(param);
  283.       if (s != null) {
  284.          if (s.substring(0, 1).equals("#")) {
  285.             s = s.substring(1);
  286.             int i = Integer.parseInt(s, 16);
  287.             return new Color(i);
  288.          } else {
  289.             return null;
  290.          }
  291.       } else {
  292.          return null;
  293.       }
  294.    }
  295.  
  296.    public void start() {
  297.       if (this.thread == null) {
  298.          this.thread = new Thread(this);
  299.          this.thread.start();
  300.       }
  301.  
  302.    }
  303.  
  304.    public void stop() {
  305.       if (this.thread != null) {
  306.          this.thread = null;
  307.       }
  308.  
  309.       if (this.sound != null) {
  310.          this.sound.stop();
  311.       }
  312.  
  313.    }
  314.  
  315.    public void run() {
  316.       Thread.currentThread().setPriority(4);
  317.       this.field_8 = -1;
  318.       this.field_9 = -1;
  319.  
  320.       while(true) {
  321.          ((Component)this).repaint();
  322.  
  323.          try {
  324.             Thread.sleep((long)this.pause);
  325.          } catch (InterruptedException var1) {
  326.          }
  327.  
  328.          this.calculatePixels();
  329.          if (this.field_8 < 0 && this.field_6 < 0) {
  330.             this.field_8 = (int)(Math.random() * (double)this.step + (double)3.0F);
  331.          } else if (this.field_8 >= 0 && this.field_6 > this.wiIm - 1) {
  332.             this.field_8 = -((int)(Math.random() * (double)this.step + (double)3.0F));
  333.          }
  334.  
  335.          this.field_6 += this.field_8;
  336.          if (this.field_9 < 0 && this.field_7 < 0) {
  337.             this.field_9 = (int)(Math.random() * (double)this.step + (double)3.0F);
  338.          } else if (this.field_9 >= 0 && this.field_7 > this.heIm - 1) {
  339.             this.field_9 = -((int)(Math.random() * (double)this.step + (double)3.0F));
  340.          }
  341.  
  342.          this.field_7 += this.field_9;
  343.       }
  344.    }
  345.  
  346.    public final void paint(Graphics g) {
  347.       if (!this.loaded) {
  348.          this.field_0.setColor(Color.white);
  349.          this.field_0.drawString("loading... please wait", 1, this.field_2 / 2);
  350.          this.loaded = true;
  351.       } else {
  352.          if (this.image != null) {
  353.             this.field_0.clearRect(0, 0, this.field_1, this.field_2);
  354.             this.field_0.drawImage(this.image, this.decx, this.decy, this);
  355.             if (this.isEnterTextEnabled) {
  356.                this.field_0.drawString(this.enterText, (this.field_1 - this.wiEnterText) / 2, this.field_2 / 2);
  357.             }
  358.  
  359.             this.image = null;
  360.          }
  361.  
  362.          g.drawImage(this.buffer, 0, 0, this);
  363.       }
  364.    }
  365.  
  366.    public final void update(Graphics g) {
  367.       this.paint(g);
  368.    }
  369.  
  370.    protected final void calculatePixels() {
  371.       for(int i = 0; i < this.heIm; ++i) {
  372.          for(int j = 0; j < this.wiIm; ++j) {
  373.             int k = this.field_6 - j;
  374.             int l = this.field_7 - i;
  375.             float rayon = (float)Math.sqrt((double)(k * k + l * l));
  376.             if (rayon < (float)this.rad) {
  377.                float ray = (float)Math.cos((double)rayon * Math.PI / (double)((float)this.rad * 1.5F));
  378.                ray *= ray;
  379.                int r = ((pix[i * this.wiIm + j] & 16711680) >> 16) + (int)((float)this.field_3 * ray);
  380.                int v = ((pix[i * this.wiIm + j] & '\uff00') >> 8) + (int)((float)this.field_4 * ray);
  381.                int b = (pix[i * this.wiIm + j] & 255) + (int)((float)this.field_5 * ray);
  382.                if (r > 255) {
  383.                   r = 255;
  384.                }
  385.  
  386.                if (v > 255) {
  387.                   v = 255;
  388.                }
  389.  
  390.                if (b > 255) {
  391.                   b = 255;
  392.                }
  393.  
  394.                pixnew[i * this.wiIm + j] = (new Color(r, v, b)).getRGB();
  395.             } else {
  396.                pixnew[i * this.wiIm + j] = pix[i * this.wiIm + j];
  397.             }
  398.          }
  399.       }
  400.  
  401.       this.image = ((Component)this).createImage(new MemoryImageSource(this.wiIm, this.heIm, pixnew, 0, this.wiIm));
  402.    }
  403.  
  404.    public URL giveURL(String url) {
  405.       try {
  406.          if (url.toUpperCase().startsWith("HTTP")) {
  407.             return new URL(url);
  408.          } else if (url.toUpperCase().startsWith("FTP")) {
  409.             int p = url.indexOf(":");
  410.             int p2 = url.indexOf(":", p + 1);
  411.             if (p2 != -1) {
  412.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  413.             }
  414.  
  415.             p = url.indexOf("%40");
  416.             if (p != -1) {
  417.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  418.             }
  419.  
  420.             return new URL(url);
  421.          } else {
  422.             return new URL(((Applet)this).getCodeBase(), url);
  423.          }
  424.       } catch (MalformedURLException e) {
  425.          System.out.println(e);
  426.          return null;
  427.       }
  428.    }
  429.  
  430.    public void mouseClicked(MouseEvent e) {
  431.    }
  432.  
  433.    public void mouseEntered(MouseEvent e) {
  434.       if (this.enterText != null) {
  435.          this.isEnterTextEnabled = true;
  436.          this.field_0.setColor(this.enterTextColor);
  437.          ((Component)this).repaint();
  438.       }
  439.  
  440.       if (this.statusBarText != null) {
  441.          ((Applet)this).showStatus(this.statusBarText);
  442.       }
  443.  
  444.       if (this.enterSound != null) {
  445.          this.enterSound.play();
  446.       }
  447.  
  448.       if (this.link != null) {
  449.          ((Component)this).setCursor(new Cursor(12));
  450.       }
  451.  
  452.    }
  453.  
  454.    public void mouseExited(MouseEvent e) {
  455.       if (this.isEnterTextEnabled) {
  456.          this.isEnterTextEnabled = false;
  457.          ((Component)this).repaint();
  458.       }
  459.  
  460.       if (this.link != null) {
  461.          ((Component)this).setCursor(new Cursor(0));
  462.       }
  463.  
  464.    }
  465.  
  466.    public void mousePressed(MouseEvent e) {
  467.       if (this.clicSound != null) {
  468.          this.clicSound.play();
  469.       }
  470.  
  471.       if (this.link != null) {
  472.          String target = ((Applet)this).getParameter("target");
  473.          if (target == null) {
  474.             target = "_blank";
  475.          }
  476.  
  477.          URL u = this.giveURL(this.link);
  478.          ((Applet)this).getAppletContext().showDocument(u, target);
  479.       }
  480.  
  481.    }
  482.  
  483.    public void mouseReleased(MouseEvent e) {
  484.    }
  485. }
  486.